/* GUI CONVERTED from soivbiq.p (converter v1.75) Sat Aug 12 17:24:49 2000 */
/* soivbiq.p - INVOICE HISTORY BILL OF MATERIAL INQUIRY                 */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* web convert soivbiq.p (converter v1.00) Tue Sep 30 12:00:52 1997 */
/* web tag in soivbiq.p (converter v1.00) Mon Sep 29 14:36:34 1997 */
/*F0PN*/ /*K0KP*/ /*                                                       */
/*V8:ConvertMode=Report                                        */
/* REVISION: 5.0      LAST MODIFIED: 01/18/90   BY:     *B511*/
/* REVISION: 6.0      LAST MODIFIED: 08/21/91   BY: bjb *D811*/
/* REVISION: 7.3      LAST MODIFIED: 09/27/92   BY: afs *G099**/
/* REVISION: 7.3      LAST MODIFIED: 11/16/92   BY: afs *G324**/
/* REVISION: 7.4      LAST MODIFIED: 11/18/96   BY: *H0PF* Suresh Nayak */
/* REVISION: 8.6      LAST MODIFIED: 10/03/97   BY: bvm *K0KP**/

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KN* myb               */

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE soivbiq_p_1 "Component"
/* MaxLen: Comment: */

&SCOPED-DEFINE soivbiq_p_2 "Qty Open"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable cust like ih_cust.
define variable inv like ih_inv_nbr.
define variable part like pt_part.
define variable qty_open like idh_qty_ship label {&soivbiq_p_2}.
define variable po like ih_po.
define variable desc1 like pt_desc1.

part = global_part.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/  part inv cust po
with frame a no-underline width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/*K0KP*/ {wbrp01.i}

repeat:

/*K0KP*/ if c-application-mode <> 'web' then
      update part inv cust po with frame a editing:

      if frame-field = "part" then do:
     /* FIND NEXT/PREVIOUS RECORD */
     {mfnp.i idh_hist part idh_part part idh_part idh_part}

     if recno <> ? then do:
        part = idh_part.
        display idh_part @ part with frame a.
        recno = ?.
     end.
      end.
      else if frame-field = "inv" then do:
     /* FIND NEXT/PREVIOUS RECORD */
     {mfnp.i idh_hist inv idh_inv_nbr inv idh_inv_nbr idh_invln}

     if recno <> ? then do:
        inv = idh_inv_nbr.
        display idh_inv_nbr @ inv with frame a.
        recno = ?.
     end.
      end.
      else if frame-field = "cust" then do:
     /* FIND NEXT/PREVIOUS RECORD */
     {mfnp.i ih_hist cust ih_cust cust ih_cust ih_cust}

     if recno <> ? then do:
        cust = ih_cust.
        display ih_cust @ cust with frame a.
        recno = ?.
     end.
      end.
      else if frame-field = "po" then do:
     /* FIND NEXT/PREVIOUS RECORD */
     {mfnp.i ih_hist po ih_po po ih_po ih_po}

     if recno <> ? then do:
        po = ih_po.
        display ih_po @ po with frame a.
        recno = ?.
     end.
      end.
      else do:
     status input.
     readkey.
     apply lastkey.
      end.
   end.

/*K0KP*/ {wbrp06.i &command = update &fields = "  part inv cust po" &frm = "a"}

/*K0KP*/ if (c-application-mode <> 'web') or
/*K0KP*/ (c-application-mode = 'web' and
/*K0KP*/ (c-web-request begins 'data')) then do:

   hide frame c.
   hide frame b.

/*K0KP*/ end.
   /* SELECT PRINTER*/
   {mfselprt.i "terminal" 80}

       {hksimsg.i """" """"}        /*fdn*/

   release ih_hist.
   if part > "" and inv > "" then do:
      find first idh_hist where idh_part = part and idh_inv_nbr = inv
      no-lock no-error.
      if available idh_hist then find ih_hist where ih_inv_nbr = idh_inv_nbr
/*G324*/                                        and idh_nbr    = ih_nbr  AND LOOKUP(ih_site,GLOBAL_user_site) > 0
      no-lock no-error.
   end.

/*G324*/ else if inv > "" then find
/*G324*/                            first
/*G324*/                                  ih_hist where ih_inv_nbr = inv
   and (ih_cust = cust or cust = "")
   and (ih_po = po or po = "")  AND LOOKUP(ih_site,GLOBAL_user_site) > 0 no-lock no-error.

   else if po > "" then find first ih_hist where ih_po = po
   and (ih_cust = cust or cust = "")  AND LOOKUP(ih_site,GLOBAL_user_site) > 0 no-lock no-error.

   else if cust > "" then find first ih_hist where ih_cust = cust  AND LOOKUP(ih_site,GLOBAL_user_site) > 0
   no-lock no-error.

   else if part > "" then do:
      find first idh_hist where idh_part = part no-lock no-error.
      if available idh_hist then find ih_hist where ih_inv_nbr = idh_inv_nbr
/*G324*/                                        and idh_nbr    = ih_nbr  AND LOOKUP(ih_site,GLOBAL_user_site) > 0
      no-lock no-error.
   end.

   else do:
/*H0PF** find first ibh_hist no-lock no-error                             */
/*H0PF*/ find first ibh_hist
/*H0PF*/ where ibh_inv_nbr >= "" and ibh_nbr >= "" and
/*H0PF*/       ibh_line >= 0 and ibh_feature >= "" and ibh_part >= ""
/*H0PF*/       no-lock no-error.

      if available ibh_hist then
/*G324*/ find ih_hist no-lock where ih_inv_nbr = ibh_inv_nbr /* no-error. */
/*G324*/                        and ih_nbr     = ibh_nbr  AND LOOKUP(ih_site, GLOBAL_user_site) > 0   no-error.
   end.

   repeat:
      if not available ih_hist then leave.

      if (ih_po = po or po = "")
      and (ih_inv_nbr = inv or inv = "")
      and (ih_cust = cust or cust = "") then

      for each idh_hist no-lock where idh_inv_nbr = ih_inv_nbr
/*G324*/                          and idh_nbr     = ih_nbr
      and (idh_part = part or part = "")
      and can-find (first ibh_hist where ibh_inv_nbr = idh_inv_nbr
/*G099*/                             and ibh_nbr  = idh_nbr
                     and ibh_line = idh_line)
      with frame b:

     if not can-find (first ibh_hist where ibh_inv_nbr = idh_inv_nbr
/*G099*/                                   and ibh_nbr  = idh_nbr
                       and ibh_line = idh_line)
      then next.

     FORM /*GUI*/ 
     idh_inv_nbr space(4) idh_line idh_part idh_desc idh_qty_inv idh_um
     with STREAM-IO /*GUI*/  frame b width 80 no-attr-space.

     /* SET EXTERNAL LABELS */
     setFrameLabels(frame b:handle).

     display idh_inv_nbr idh_line idh_part idh_desc idh_qty_inv idh_um WITH STREAM-IO /*GUI*/ .

     find pt_mstr no-lock where pt_part = idh_part no-error.
     if available pt_mstr then display pt_desc1 @ idh_desc WITH STREAM-IO /*GUI*/ .

     for each ibh_hist where ibh_inv_nbr = idh_inv_nbr
/*G324*/                     and ibh_nbr     = idh_nbr
     and ibh_line = idh_line no-lock with frame c:

        FORM /*GUI*/  space(3)
        ibh_feature ibh_part column-label {&soivbiq_p_1}
        idh_desc ibh_qty_req pt_um
        with STREAM-IO /*GUI*/  frame c width 80 no-attr-space.

        /* SET EXTERNAL LABELS */
        setFrameLabels(frame c:handle).

        find pt_mstr where pt_part = ibh_part no-lock no-error.
        if available pt_mstr and pt_desc2 > ""
        and frame-down - frame-line < 1
        and frame-line <> 0
        then down 1.

        display ibh_feature ibh_part ((idh_qty_inv / idh_qty_ord) *
            ibh_qty_req) @ ibh_qty_req WITH STREAM-IO /*GUI*/ .

        if available pt_mstr then do with frame c:
           display pt_desc1 @ idh_desc pt_um WITH STREAM-IO /*GUI*/ .
           if pt_desc2 > "" then do with frame c:
          down 1.
          display pt_desc2 @ idh_desc WITH STREAM-IO /*GUI*/ .
           end.
        end.
     end.

     
/*GUI*/ {mfguirex.i  "false"} /*Replace mfrpexit*/
       /*D811*/
      end.

      
/*GUI*/ {mfguirex.i  "false"} /*Replace mfrpexit*/
  /*D811*/

      display "" with frame d no-box STREAM-IO /*GUI*/ .
      hide frame d no-pause.

/*G324** (Altered code since invoice consolidation could result in */
/*G324** multiple ih_hist records with the same invoice number)    */
/*G324** if inv > "" then leave. **/
/*G324*/ if inv > "" then repeat:
/*G324*/    find next ih_hist where ih_inv_nbr = inv
/*G324*/                        and (ih_cust = cust or cust = "")
/*G324*/                        and (ih_po = po or po = "") AND LOOKUP(ih_site,GLOBAL_user_site) > 0
/*G324*/                      no-lock no-error.
/*G324*/    if not available ih_hist then leave.
/*G324*/    if can-find (first ibh_hist where ibh_inv_nbr = ih_inv_nbr
/*G324*/                                  and ibh_nbr     = ih_nbr )
/*G324*/     then leave.
/*G324*/ end.

      else if po > "" then repeat:
     find next ih_hist where ih_po = po
     and (ih_cust = cust or cust = "") AND LOOKUP(ih_site,GLOBAL_user_site) > 0 no-lock no-error.
     if not available ih_hist then leave.
     if can-find (first ibh_hist where ibh_inv_nbr = ih_inv_nbr
/*G324*/                               and ibh_nbr     = ih_nbr )
/*G324*/  then leave.
      end.

      else if cust > "" then repeat:
     find next ih_hist where ih_cust = cust AND LOOKUP(ih_site,GLOBAL_user_site) > 0 no-lock no-error.
     if not available ih_hist then leave.
/*G324*/ if can-find (first ibh_hist where ibh_inv_nbr = ih_inv_nbr
/*G324*/                               and ibh_nbr     = ih_nbr )
/*G324*/  then leave.
      end.

      else if part > "" then do:
     find first idh_hist where idh_part = part and idh_inv_nbr > ih_inv_nbr
     and can-find (first ibh_hist where ibh_inv_nbr = idh_inv_nbr
/*G099*/                                and ibh_nbr  = idh_nbr
                    and ibh_line = idh_line)
     no-lock no-error.
     if available idh_hist then find ih_hist where ih_inv_nbr = idh_inv_nbr
/*G324*/                                           and idh_nbr    = ih_nbr  AND LOOKUP(ih_site,GLOBAL_user_site) > 0
     no-lock no-error.
     else release ih_hist.
      end.

      else do:
     find first ibh_hist no-lock where ibh_inv_nbr > ih_inv_nbr no-error.
     if available ibh_hist then
/*G324*/ find ih_hist no-lock where ih_inv_nbr = ibh_inv_nbr /* no-error. */
/*G324*/                        and ih_nbr     = ibh_nbr    AND LOOKUP(ih_site,GLOBAL_user_site) > 0  no-error.
     else release ih_hist.
      end.

   end.
   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

   {mfmsg.i 8 1}

end.

/*K0KP*/ {wbrp04.i &frame-spec = a}
